using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.Popup
{
    /// <summary>
    /// author: XCH
    /// </summary>
    public partial class PopupNewsBarMsgForm : BasePage_SOM
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.SetLanguage();
                GetMessageByID();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(ChangeLanguage_Function);
        }

        void ChangeLanguage_Function(object sender, EventArgs e)
        {
            SetLanguage();
        }

        /// <summary>
        /// get the word of the page by lanuage code
        /// </summary>
        private void SetLanguage()
        {
            this.lblTitle.Text = this.GetLabel("SOM_NewsBarMsgTitle",true);
            this.lblStartTime.Text = this.GetLabel("SOM_NewsBarMsgStartTime", true);
            this.lblMsgContent.Text = this.GetLabel("SOM_NewsBarMsgContent", true);
            this.lblEndTime.Text = this.GetLabel("SOM_NewsBarMsgEndTime", true);
        }

        /// <summary>
        /// click the Message title,then get the message's content
        /// </summary>
        private void GetMessageByID()
        {
            string MessageID = Request.QueryString["MessageID"];//get the id to select content
            DataTable dt = new DataTable();
            dt = DAL.SOM.CodeSetup.ReminderMsgDa.GetNewsBarMsgByID(this.LangCode,MessageID);
            if (dt.Rows.Count > 0)
            {
                txtNewsTitle.Text = dt.Rows[0].ItemArray[2].ToString();//get the title
                txtNewsTitle.Enabled = false;
                string EventNo = dt.Rows[0].ItemArray[4].ToString();//get the EventNo to replace the string 
                string htmlstr = dt.Rows[0].ItemArray[3].ToString();//get the message content
                lblContent.Text = htmlstr.Replace("[#EventNo]", EventNo);//replace the string 
                txtStartTime.Text = dt.Rows[0].ItemArray[0].ToString();//get the start time
                txtEndTime.Text = dt.Rows[0].ItemArray[1].ToString();//get the end time
                txtStartTime.Enabled = false;
                txtEndTime.Enabled = false;
            }
            else
            {
                lblTitle.Text = this.GetLabel("SOM_NewsBarMsgNoData");
                txtNewsTitle.Visible = false;
                lblStartTime.Visible = false;
                lblMsgContent.Visible = false;
                lblEndTime.Visible = false;
                lblContent.Visible = false;
                txtEndTime.Visible = false;
                txtStartTime.Visible = false;
            }
        }
    }
}
